package cn.manyufun.myf.common.webview;

import android.app.Activity;
import android.util.Log;
import android.webkit.JavascriptInterface;
import android.webkit.WebView;

/**
 * Created by Xiao on 2018-02-12.
 */

public class PostInterceptJavascriptInterface {
    public static final String TAG = "xwxJavascriptInterface";

    private Activity activity;
    private BaseWebView mBaseWebView;
    private WebView webView;

    public PostInterceptJavascriptInterface(BaseWebView baseWebView) {
        activity = baseWebView.activity;
        webView = baseWebView.webView;
        mBaseWebView = baseWebView;

    }


    @JavascriptInterface
    public void share(String data) {
        Log.i("xwx_api_share", data);
//        try {
//            JSONObject json = new JSONObject(data);
//            String url = json.getString("url");
//            String title = json.getString("title");
//            String img = json.getString("img");
//            String type = json.getString("type");
//            final UmShare umShare = new UmShare(activity, title, url, img);
//            switch (type) {
//                case "wechat":
//                    activity.runOnUiThread(new Runnable() {
//                        @Override
//                        public void run() {
//                            umShare.Share(SHARE_MEDIA.WEIXIN, shareCallback);
//                        }
//                    });
//                    break;
//                case "wechattime":
//                    activity.runOnUiThread(new Runnable() {
//                        @Override
//                        public void run() {
//                            umShare.Share(SHARE_MEDIA.WEIXIN_CIRCLE, shareCallback);
//                        }
//                    });
//                    break;
//                case "qq":
//                    activity.runOnUiThread(new Runnable() {
//                        @Override
//                        public void run() {
//                            umShare.Share(SHARE_MEDIA.QQ, shareCallback);
//                        }
//                    });
//                    break;
//                case "sina":
//                    activity.runOnUiThread(new Runnable() {
//                        @Override
//                        public void run() {
//                            umShare.Share(SHARE_MEDIA.SINA, shareCallback);
//                        }
//                    });
//                    break;
//            }
//        } catch (JSONException e) {
//            Log.e("xwx_api_share", e.getMessage());
//        }
    }


    @JavascriptInterface
    public void favor(long articleID, long replyID) {
        mBaseWebView.mCallback.favor(articleID, replyID);
    }

    @JavascriptInterface
    public void like(long articleID) {
        mBaseWebView.mCallback.like(articleID);
    }

    @JavascriptInterface
    public void reply(long articleID, long replyID) {
        mBaseWebView.mCallback.reply(articleID, replyID);
    }

    @JavascriptInterface
    public void openCommonList(int type, long comicsId) {
        mBaseWebView.mCallback.openCommonList(type, comicsId);
    }

    @JavascriptInterface
    public void openComicsDetail(long comicsId) {
        mBaseWebView.mCallback.openComicsDetail(comicsId);
    }

    @JavascriptInterface
    public void openImageDetail(String imgUrl) {
        mBaseWebView.mCallback.openImageDetail(imgUrl);
    }
}
